package com.robusta.app.auth.model;

import com.robusta.app.domain.user.UserType;
import com.robusta.app.model.persistence.AuditListener;
import com.robusta.app.model.persistence.Creatable;
import com.robusta.app.model.persistence.Updatable;
import org.apache.commons.lang3.builder.ToStringBuilder;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "USER") @EntityListeners(AuditListener.class)
public class UserModel extends com.robusta.app.model.persistence.Entity implements Serializable, Creatable, Updatable {
    @Id
    @Column(name = "USER_ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "USER_NAME", nullable = false)
    private String name;
    @Column(name = "LOGIN_NAME", nullable = false)
    private String loginName;
    @Column(name = "PASSWORD", nullable = false)
    private String password;
    @Column(name = "USER_TYPE", nullable = false)
    @Enumerated(EnumType.STRING)
    private UserType userType;
    @Column(name = "EMAIL", nullable = false)
    private String email;

    public UserModel() {} // for JPA.

    public UserModel(Long id, String name, String loginName, String password, UserType userType, String email) {
        this.id = id;
        this.name = name;
        this.loginName = loginName;
        this.password = password;
        this.userType = userType;
        this.email = email;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getLoginName() {
        return loginName;
    }

    public String getPassword() {
        return password;
    }

    public UserType getUserType() {
        return userType;
    }

    public String getEmail() {
        return email;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
